package com.example.j20240313springmvc.controller;

import com.example.j20240313springmvc.mapper.MessageMapper;
import com.example.j20240313springmvc.model.Message;
import com.example.j20240313springmvc.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;
    @RequestMapping("/publish")
    public Boolean publish(Message message) {
        if(!StringUtils.hasLength(message.getFrom())||
                !StringUtils.hasLength(message.getTo())||
                !StringUtils.hasLength(message.getSay())) {
            return false;
        }
        return messageService.publish(message);
    }
    @RequestMapping("/getMessages")
    public List<Message> getMessages() {
        return messageService.getMessages();
    }
}
